home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Tools / Mac F2C 1.3.3 / Test Project ƒ / F2Cmain.cp < prev    next >
Text File  |  1996-04-14  |  5KB  |  240 lines

  1. /* STARTUP PROCEDURE FOR TRANSLATED FORTRAN PROGRAMS */
  2.  
  3. /* IMT 9Sep95  Modified for new conditional compile mechanism */
  4. #if ( defined(THINK_C) || defined(THINK_CPLUS) )
  5. #define TPM_F2C            
  6. #endif
  7.  
  8. /* IMT 9Sep95  Modified for new conditional compile mechanism */
  9. #if (  defined(SYMANTEC_C) || defined(SYMANTEC_CPLUS) )
  10. #define SPM_F2C
  11. #endif
  12.  
  13. /* IMT 9Sep95  Modified for new conditional compile mechanism */
  14. #if !defined(MPW_CW_F2C) && ( defined(__MWERKS__) )
  15. #define CW_F2C
  16. #endif
  17.  
  18. /* IMT 9Sep95  THINK Project Manager specific includes */
  19. #ifdef TPM_F2C
  20. #include <console.h>
  21. #endif                    
  22.  
  23. /* IMT 9Sep95  Symantec Project Manager specific includes */
  24. #ifdef SPM_F2C 
  25. #include <console.h>    
  26. #endif                    
  27.  
  28. /* IMT 9Sep95  CodeWarrior specific includes */
  29. #ifdef CW_F2C
  30. #include <console.h>
  31. #include <SIOUX.h>
  32. #endif
  33.  
  34. /* IMT 9Sep95  MPW CodeWarrior specific includes */
  35. #ifdef MPW_CW_F2C
  36. #include <console.h>
  37. #endif
  38.  
  39.  
  40. /* IMT 12Apr96  Include files for adjusting the stack size in 68K */
  41. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C) 
  42. #if GENERATING68K
  43. #include <ConditionalMacros.h>
  44. #include <LowMem.h>
  45. #include <Memory.h>
  46. #endif /* GENERATING68K */
  47. #endif /* Macintosh C compilers */
  48.  
  49.  
  50. /* IMT 09Sep95  Prototypes for new functions that add multitasking */
  51. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C) 
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. void InitMultiTask( long sliceInMicroSecs );
  56. void EndMultiTask( void );
  57. #ifdef __cplusplus
  58. }
  59. #endif
  60. #endif /* Macintosh C compilers */
  61.  
  62.  
  63. /* IMT 10Sep95  Declare jump buffer used to recover from exception exits & aborts */
  64. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C) 
  65. #include <setjmp.h>
  66. #ifdef __cplusplus
  67. extern "C" {
  68. #endif
  69. jmp_buf gRecoverToConsole;
  70. #ifdef __cplusplus
  71. }
  72. #endif
  73. #endif /* Macintosh C compilers */
  74.  
  75.  
  76. #include "stdio.h"
  77. #include "signal.h"
  78.  
  79. #ifndef SIGIOT
  80. #ifdef SIGABRT
  81. #define SIGIOT SIGABRT
  82. #endif
  83. #endif
  84.  
  85.  
  86. #ifndef KR_headers
  87. #include "stdlib.h"
  88. #endif
  89. #ifdef __cplusplus
  90. extern "C" {
  91. #endif
  92.  
  93. #ifdef NO__STDC
  94. #define ONEXIT onexit
  95. extern void f_exit();
  96. #else
  97. #ifndef KR_headers
  98. extern void f_exit(void);
  99. #ifndef NO_ONEXIT
  100. #define ONEXIT atexit
  101. extern int atexit(void (*)(void));
  102. #endif
  103. #else
  104. #ifndef NO_ONEXIT
  105. #define ONEXIT onexit
  106. extern void f_exit();
  107. #endif
  108. #endif
  109. #endif
  110.  
  111. #ifdef KR_headers
  112. extern void f_init(), sig_die();
  113. extern int MAIN__();
  114. #define Int /* int */
  115. #else
  116. extern void f_init(void), sig_die(char*, int);
  117. extern int MAIN__(void);
  118. #define Int int
  119. #endif
  120.  
  121. static void sigfdie(Int n)
  122. {
  123. sig_die("Floating Exception", 1);
  124. }
  125.  
  126.  
  127. static void sigidie(Int n)
  128. {
  129. sig_die("IOT Trap", 1);
  130. }
  131.  
  132. #ifdef SIGQUIT
  133. static void sigqdie(Int n)
  134. {
  135. sig_die("Quit signal", 1);
  136. }
  137. #endif
  138.  
  139.  
  140. static void sigindie(Int n)
  141. {
  142. sig_die("Interrupt", 0);
  143. }
  144.  
  145. static void sigtdie(Int n)
  146. {
  147. sig_die("Killed", 0);
  148. }
  149.  
  150. #ifdef SIGTRAP
  151. static void sigtrdie(Int n)
  152. {
  153. sig_die("Trace trap", 1);
  154. }
  155. #endif
  156.  
  157.  
  158.  
  159. int xargc;
  160. char **xargv;
  161.  
  162. #ifdef KR_headers
  163. main(argc, argv) int argc; char **argv;
  164. #else
  165. main(int argc, char **argv)
  166. #endif
  167. {
  168.  
  169. /* IMT 12Apr96  Add conditional code to increase 68K stack size */
  170. /*              Adjust the following #define as needed */
  171. #define kDesiredStackSize  (40*1024L)     /* 68K stack size set to 40K bytes */
  172. #if GENERATING68K && defined(kDesiredStackSize)    
  173.     if ( kDesiredStackSize > LMGetDefltStack() )
  174.     {
  175.         Ptr newApplLimit = GetApplLimit() - (kDesiredStackSize - LMGetDefltStack());
  176.         SetApplLimit( newApplLimit );
  177.     }
  178. #endif    /* increase stack size */
  179.  
  180. /* IMT 09Sep95  Add file re-direction and command-line arguments dialog */
  181. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C) 
  182.     argc = ccommand( &argv );
  183. #endif /* Macintosh C compilers */
  184.  
  185. /* IMT 14Sep95  Initialize multi-tasking code for CodeWarrior */
  186. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C) 
  187.     InitMultiTask( 0 );
  188. #endif /* CodeWarrior */
  189.  
  190. xargc = argc;
  191. xargv = argv;
  192. signal(SIGFPE, sigfdie);    /* ignore underflow, enable overflow */
  193. #ifdef SIGIOT
  194. signal(SIGIOT, sigidie);
  195. #endif
  196. #ifdef SIGTRAP
  197. signal(SIGTRAP, sigtrdie);
  198. #endif
  199. #ifdef SIGQUIT
  200. if(signal(SIGQUIT,sigqdie) == SIG_IGN)
  201.     signal(SIGQUIT, SIG_IGN);
  202. #endif
  203. if(signal(SIGINT, sigindie) == SIG_IGN)
  204.     signal(SIGINT, SIG_IGN);
  205. signal(SIGTERM,sigtdie);
  206.  
  207. #ifdef pdp11
  208.     ldfps(01200); /* detect overflow as an exception */
  209. #endif
  210.  
  211. f_init();
  212. #ifndef NO_ONEXIT
  213. ONEXIT(f_exit);
  214. #endif
  215.  
  216. /* IMT 10Sep95:  Set-up for returning to console from exceptional exits and aborts */
  217. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C)
  218. if ( setjmp(gRecoverToConsole) == 0 )
  219. #endif /* Macintosh C compilers */
  220.  
  221. MAIN__();
  222.  
  223. /* IMT 10Sep95:  Close out multi-tasking code for CW, SPM, TPM */
  224. #if defined(TPM_F2C) || defined(SPM_F2C) || defined(CW_F2C) 
  225. EndMultiTask();
  226. puts( "\nExecution complete.\n" );
  227. #endif /* Macintosh C compilers */
  228.  
  229.  
  230. #ifdef NO_ONEXIT
  231. f_exit();
  232. #endif
  233. exit(0);    /* exit(0) rather than return(0) to bypass Cray bug */
  234. return 0;    /* For compilers that complain of missing return values; */
  235.             /* others will complain that this is unreachable code. */
  236. }
  237. #ifdef __cplusplus
  238.     }
  239. #endif
  240.